<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html"
      xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/QR.css">
    <script src="${pageContext.request.contextPath}/static/bootstrap-3.4.1-dist/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.8.3-min.js"></script>
    <title>购物车</title>

    <script>
        window.onload = function (){
            document.getElementById("firstCB").onclick = function (){
                //获取后面所有的checkbox
                var cbs = document.getElementsByName("pid");
                //3.遍历
                for (var i = 0; i < cbs.length; i++) {
                    //设置这些cbs[i]的check状态 为最顶上哪个checkbox的状态
                    cbs[i].checked = this.checked;
                }
            }

        }
    </script>
    <script>
        function AddColl(uid,pid){
            if(confirm("您确定要收藏吗？")){
                location.href="${pageContext.request.contextPath}/CollectionServlet?action=AddCollection1&uid="+uid+"&pid="+pid;
            }
        }

        function Addnum(id,uid){
            location.href="${pageContext.request.contextPath}/CartServlet?action=AddNum&id="+id+"&uid="+uid;
        }

        function Reducenum(id,uid){
            location.href="${pageContext.request.contextPath}/CartServlet?action=ReduceNum&id="+id+"&uid="+uid;
        }
    </script>
</head>

<body>
<c:if test="${empty user}">
    <div class="top-nav">
        <div class="container clearf">
            <div class="left">
                <a href="${pageContext.request.contextPath}/Index.jsp" class="item">首页</a>
            </div>

            <div class="right">
                <a href="${pageContext.request.contextPath}/Register.jsp" class="item">注册/登录</a>
            </div>
        </div>
    </div>
</c:if>

<c:if test="${not empty user}">
    <div class="top-nav">
        <div class="container clearf">
            <div class="left">
                <a href="${pageContext.request.contextPath}/UserServlet?action=BackToIndex&id=${user.id}" class="item">首页</a>
            </div>

            <div class="right">
                <div class="dropdown item">
                    <a class="item">欢迎您，${user.username}</a>
                    <div class="dropdown-content">
                        <a href="${pageContext.request.contextPath}/UserServlet?action=UserInf&id=${user.id}">个人信息</a>
                        <a href="${pageContext.request.contextPath}/OrdersServlet?action=Orderselect&uid=${user.id}">我的订单</a>
                        <a href="${pageContext.request.contextPath}/CartServlet?action=IntoCart&id=${user.id}">我的购物车</a>
                        <a href="${pageContext.request.contextPath}/CollectionServlet?action=IntoCollection&id=${user.id}">我的收藏夹</a>
                        <a href="${pageContext.request.contextPath}/UserServlet?action=LogOut">退出登录</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</c:if>


<div class="header">
    <div class="container clearf">
        <div class="col-1 logo">购物车</div>
    </div>
</div>

<div class="car">
    <form action="${pageContext.request.contextPath}/OrdersServlet?action=buyorders&uid=${user.id}" name="car" method="post">
        <div class="container clearf">
            <div class="col-5">商品信息</div>
            <div class="col-1">单价</div>
            <div class="col-2" style="  text-align: left;">数量</div>
            <div class="col-1">小计</div>
            <div class="col-1">操作</div>
        </div>
        <HR align=center width=100% color=#dedede SIZE=1>
    <c:forEach items="${product}" var="p" varStatus="i">
        <div class="container clearf">
            <div class="col-1">
                <input name="cid" type="checkbox" value="${p.id}">
            </div>
            <div class="col-4">
                <img class="col-4" src="${pageContext.request.contextPath}/img/${p.picture}">
                <a class="col-6" style="text-align: center" href="${pageContext.request.contextPath}/ProductServlet?action=IntoProduct&uid=${user.id}&pid=${p.productid}">${p.name}</a>
            </div>
            <div class="col-1" style="color: black">￥${p.price}</div>
            <div class="col-2">
                <ul class="btn-numbox">
                    <li>
                        <ul class="count">
                            <li><span id="num-jian" class="num-jian" onclick="Reducenum(${p.id},${user.id})">-</span></li>
                            <li><input type="text" class="input-num" name="cnum" id="input-num" value="${p.cnum}" /></li>
                            <li><span id="num-jia" class="num-jia" onclick="Addnum(${p.id},${user.id})">+</span></li>
                        </ul>
                    </li>
                    <li><span class="kucun">（库存:</span><span class="kucun">${p.num}</span><span class="kucun">)</span></li>
                </ul>
            </div>
            <div class="col-1" style="color: black">￥${p.totalprice}</div>
            <div class="col-1">
                <a href="javascript:AddColl(${user.id},${p.productid});">添加收藏</a>
                <a href="${pageContext.request.contextPath}/CartServlet?action=DelCartItem&uid=${user.id}&pid=${p.id}">删除</a>
            </div>
        </div>
        </br>
        <HR align=center width=100% color=#dedede SIZE=3>
    </c:forEach>

        <div class="container clearf">
            <div class="down">
                <div style="float: left" class="col-5">
                    <input name="check" type="checkbox" id="firstCB">
                    全选
                </div>
                <div  class="col-5" style="float: right">
                    <div class="col-5" style="text-align: right;"></div>
                    <div class="col-2" style="color: red"></div>
                    <button type="submit"  title="购买" class="An1" style="float: left;margin-left: 50px;">购买</button>
                </div>
            </div>
        </div>
    </form>
</div>


<div class="footer">
    <div class="container clearf">
        <div class="">© 2021 版权所有 粤ICP备11111111号 |隐私政策|用户使用协议|资质证照|知识产权</div>
    </div>
</div>

</body>
</html>
